home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0183_Delete files to recyle bin.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-11-29  |  1.3 KB  |  51 lines

  1. { This function deletes a file in Windows 95 and moves it to the recycle bin.
  2.   It returns True if the operation is successful, and False otherwise
  3.  
  4.   Syntax:
  5.  
  6.           x := RecycleFile(Filename);
  7.  
  8.           *** Distribute this file freely
  9.  
  10.           This unit written by John Ruzicka 75160.2376@compuserve.com
  11.           based on code from Dennis Passmore and Steve Schafer on the
  12.           BDELPHI forum
  13.  
  14.   }
  15.  
  16. unit Recycle;
  17.  
  18. interface
  19.  
  20. uses Windows, Messages, SysUtils, Classes, Controls, Forms, Dialogs, ShellAPI;
  21.  
  22. function RecycleFile(FileToRecycle: string): boolean;
  23.  
  24. implementation
  25.  
  26. function RecycleFile(FileToRecycle: TFilename): boolean;
  27. var Struct: TSHFileOpStruct;
  28.     pFromc: array[0..255] of char;
  29.     Resultval: integer;
  30. begin
  31.    if not FileExists(FileToRecycle) then begin
  32.       RecycleFile := False;
  33.       exit;
  34.    end
  35.    else begin
  36.       fillchar(pfromc,sizeof(pfromc),0);
  37.       StrPcopy(pfromc,expandfilename(FileToRecycle)+#0#0);
  38.       Struct.wnd := 0;
  39.       Struct.wFunc := FO_DELETE;
  40.       Struct.pFrom := pFromC;
  41.       Struct.pTo   := nil;
  42.       Struct.fFlags:= FOF_ALLOWUNDO;
  43.       Struct.fAnyOperationsAborted := false;
  44.       Struct.hNameMappings := nil;
  45.       Resultval := ShFileOperation(Struct);
  46.       RecycleFile := (Resultval = 0);
  47.    end;
  48. end;
  49.  
  50. end.
  51.